<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录注册 - 外卖平台</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: 'Microsoft YaHei', Arial, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 20px;
            position: relative;
            overflow: hidden;
        }
        
        /* 背景动画 */
        body::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: 
                radial-gradient(circle at 20% 80%, rgba(120, 119, 198, 0.3) 0%, transparent 50%),
                radial-gradient(circle at 80% 20%, rgba(255, 119, 198, 0.3) 0%, transparent 50%),
                radial-gradient(circle at 40% 40%, rgba(120, 219, 255, 0.2) 0%, transparent 50%);
            animation: backgroundShift 20s ease-in-out infinite;
            z-index: -1;
        }
        
        @keyframes backgroundShift {
            0%, 100% { opacity: 1; }
            50% { opacity: 0.8; }
        }
        
        .container {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(20px);
            border-radius: 20px;
            padding: 40px;
            box-shadow: 0 25px 50px rgba(0,0,0,0.15);
            width: 100%;
            max-width: 500px;
            position: relative;
            z-index: 1;
        }
        
        .header {
            text-align: center;
            margin-bottom: 30px;
        }
        
        .header h1 {
            font-size: 2.8rem;
            color: #333;
            margin-bottom: 10px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        
        .header p {
            color: #666;
            font-size: 1.1rem;
        }
        
        .tabs {
            display: flex;
            margin-bottom: 30px;
            background: #f8f9fa;
            border-radius: 12px;
            padding: 4px;
            position: relative;
        }
        
        .tab {
            flex: 1;
            padding: 15px;
            border: none;
            background: transparent;
            cursor: pointer;
            font-size: 16px;
            font-weight: 600;
            color: #666;
            border-radius: 8px;
            transition: all 0.3s ease;
            position: relative;
            z-index: 2;
        }
        
        .tab.active {
            background: white;
            color: #667eea;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        
        .form-group {
            margin-bottom: 20px;
            position: relative;
        }
        
        .form-group label {
            display: block;
            margin-bottom: 8px;
            color: #333;
            font-weight: 600;
        }
        
        .form-group input {
            width: 100%;
            padding: 15px 20px;
            border: 2px solid #e1e5e9;
            border-radius: 12px;
            font-size: 16px;
            transition: all 0.3s ease;
            background: rgba(255, 255, 255, 0.8);
            backdrop-filter: blur(10px);
        }
        
        .form-group input:focus {
            outline: none;
            border-color: #667eea;
            background: rgba(255, 255, 255, 0.95);
            box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
            transform: translateY(-2px);
        }
        
        .form-group input::placeholder {
            color: rgba(0, 0, 0, 0.4);
        }
        
        .user-types {
            display: flex;
            gap: 10px;
            margin-bottom: 20px;
        }
        
        .user-type {
            flex: 1;
            padding: 15px 10px;
            border: 2px solid #e1e5e9;
            border-radius: 12px;
            background: rgba(255, 255, 255, 0.8);
            backdrop-filter: blur(10px);
            cursor: pointer;
            text-align: center;
            font-weight: 600;
            color: #666;
            transition: all 0.3s ease;
            position: relative;
            overflow: hidden;
        }
        
        .user-type::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            opacity: 0;
            transition: opacity 0.3s ease;
        }
        
        .user-type.active {
            border-color: #667eea;
            color: white;
            transform: translateY(-2px);
            box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
        }
        
        .user-type.active::before {
            opacity: 1;
        }
        
        .user-type span {
            position: relative;
            z-index: 2;
        }
        
        .btn {
            width: 100%;
            padding: 16px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border: none;
            border-radius: 12px;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            margin-top: 10px;
            position: relative;
            overflow: hidden;
        }
        
        .btn::before {
            content: '';
            position: absolute;
            top: 0;
            left: -100%;
            width: 100%;
            height: 100%;
            background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
            transition: left 0.5s ease;
        }
        
        .btn:hover::before {
            left: 100%;
        }
        
        .btn:hover {
            transform: translateY(-3px);
            box-shadow: 0 10px 25px rgba(102, 126, 234, 0.4);
        }
        
        .btn:active {
            transform: translateY(-1px);
        }
        
        .message {
            padding: 12px 16px;
            border-radius: 8px;
            margin-bottom: 20px;
            font-size: 0.9rem;
            font-weight: 500;
            text-align: center;
            animation: slideIn 0.3s ease;
        }
        
        @keyframes slideIn {
            from {
                opacity: 0;
                transform: translateY(-10px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .message.success {
            background: rgba(46, 213, 115, 0.1);
            border: 1px solid rgba(46, 213, 115, 0.3);
            color: #2ed573;
        }
        
        .message.error {
            background: rgba(255, 71, 87, 0.1);
            border: 1px solid rgba(255, 71, 87, 0.3);
            color: #ff4757;
        }
        
        .hidden {
            display: none;
        }
        
        .back-btn {
            position: absolute;
            top: 20px;
            left: 20px;
            background: rgba(255, 255, 255, 0.2);
            border: none;
            border-radius: 50%;
            width: 45px;
            height: 45px;
            cursor: pointer;
            color: white;
            font-size: 18px;
            transition: all 0.3s ease;
            backdrop-filter: blur(10px);
        }
        
        .back-btn:hover {
            background: rgba(255, 255, 255, 0.3);
            transform: scale(1.1);
        }
        
        .logged-in-state {
            text-align: center;
            padding: 20px;
        }
        
        .user-avatar {
            width: 80px;
            height: 80px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            margin: 0 auto 20px;
            font-size: 2rem;
            color: white;
        }
        
        .user-details h3 {
            color: #333;
            margin-bottom: 5px;
            font-size: 1.5rem;
        }
        
        .user-details p {
            color: #666;
            margin-bottom: 20px;
        }
        
        .action-buttons {
            display: flex;
            gap: 15px;
            justify-content: center;
        }
        
        .action-btn {
            padding: 12px 24px;
            border: none;
            border-radius: 8px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            display: flex;
            align-items: center;
            gap: 8px;
        }
        
        .action-btn.primary {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
        }
        
        .action-btn.secondary {
            background: #6c757d;
            color: white;
        }
        
        .action-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(0,0,0,0.2);
        }
        
        .btn-icon {
            font-size: 1.2rem;
        }
        
        /* 响应式设计 */
        @media (max-width: 480px) {
            .container {
                margin: 20px;
                padding: 30px 25px;
            }
            
            .header h1 {
                font-size: 2.2rem;
            }
            
            .form-group input {
                padding: 12px 16px;
            }
            
            .btn {
                padding: 12px;
            }
        }
    </style>
</head>
<body>
    <button class="back-btn" onclick="goBack()">←</button>
    
    <div class="container">
        <div class="header">
            <h1>🍽️ 外卖平台</h1>
            <p>专业的餐饮配送服务平台</p>
        </div>
        
        <div class="tabs">
            <button class="tab active" onclick="showLogin()">登录</button>
            <button class="tab" onclick="showRegister()">注册</button>
        </div>
        
        <!-- 登录表单 -->
        <div id="loginForm">
            <div class="user-types">
                <div class="user-type active" data-type="user" onclick="selectUserType('user')">
                    <span>👤 用户</span>
                </div>
                <div class="user-type" data-type="merchant" onclick="selectUserType('merchant')">
                    <span>🏪 商家</span>
                </div>
                <div class="user-type" data-type="rider" onclick="selectUserType('rider')">
                    <span>🏍️ 骑手</span>
                </div>
            </div>
            
            <form onsubmit="handleLogin(event)">
                <div class="form-group">
                    <label>用户名</label>
                    <input type="text" id="loginUsername" placeholder="请输入用户名" required>
                </div>
                <div class="form-group">
                    <label>密码</label>
                    <input type="password" id="loginPassword" placeholder="请输入密码" required>
                </div>
                <button type="submit" class="btn">登录</button>
            </form>
        </div>
        
        <!-- 注册表单 -->
        <div id="registerForm" class="hidden">
            <div class="user-types">
                <div class="user-type active" data-type="user" onclick="selectUserType('user')">
                    <span>👤 用户</span>
                </div>
                <div class="user-type" data-type="merchant" onclick="selectUserType('merchant')">
                    <span>🏪 商家</span>
                </div>
                <div class="user-type" data-type="rider" onclick="selectUserType('rider')">
                    <span>🏍️ 骑手</span>
                </div>
            </div>
            
            <form onsubmit="handleRegister(event)">
                <div class="form-group">
                    <label>用户名</label>
                    <input type="text" id="regUsername" placeholder="请输入用户名" required>
                </div>
                <div class="form-group">
                    <label>密码</label>
                    <input type="password" id="regPassword" placeholder="请输入密码" required>
                </div>
                <div class="form-group">
                    <label>手机号</label>
                    <input type="text" id="regPhone" placeholder="请输入手机号" required>
                </div>
                <div class="form-group">
                    <label>邮箱</label>
                    <input type="email" id="regEmail" placeholder="请输入邮箱" required>
                </div>
                <button type="submit" class="btn">注册</button>
            </form>
        </div>
        
        <div id="message"></div>
        
        <!-- 已登录用户 -->
        <div id="loggedInUser" class="hidden">
            <div class="logged-in-state">
                <div class="user-avatar">
                    <span>👤</span>
                </div>
                <div class="user-details">
                    <h3>欢迎回来！</h3>
                    <p>用户：<span id="loggedInUserName"></span></p>
                </div>
                <div class="action-buttons">
                    <button class="action-btn primary" onclick="goToMain()">
                        <span class="btn-icon">🏠</span>
                        进入主页面
                    </button>
                    <button class="action-btn secondary" onclick="logout()">
                        <span class="btn-icon">🚪</span>
                        退出登录
                    </button>
                </div>
            </div>
        </div>
    </div>

    <script>
        // 用户数据存储
        let users = JSON.parse(localStorage.getItem('users') || '[]');
        let currentUser = null;
        let currentUserType = 'user';
        
        // 初始化测试用户
        if (users.length === 0) {
            users = [
                { id: 1, username: 'admin', password: '1234', phone: '13800138000', email: 'admin@test.com', type: 'user', name: '管理员' },
                { id: 2, username: 'merchant1', password: '1234', phone: '13800138001', email: 'merchant@test.com', type: 'merchant', name: '测试商家' },
                { id: 3, username: 'rider1', password: '1234', phone: '13800138002', email: 'rider@test.com', type: 'rider', name: '测试骑手' }
            ];
            localStorage.setItem('users', JSON.stringify(users));
        }
        
        function showMessage(text, type) {
            const messageDiv = document.getElementById('message');
            messageDiv.innerHTML = `<div class="message ${type}">${text}</div>`;
            setTimeout(() => {
                messageDiv.innerHTML = '';
            }, 3000);
        }
        
        function showLogin() {
            document.getElementById('loginForm').classList.remove('hidden');
            document.getElementById('registerForm').classList.add('hidden');
            document.querySelectorAll('.tab')[0].classList.add('active');
            document.querySelectorAll('.tab')[1].classList.remove('active');
            resetUserTypes('loginForm');
        }
        
        function showRegister() {
            document.getElementById('loginForm').classList.add('hidden');
            document.getElementById('registerForm').classList.remove('hidden');
            document.querySelectorAll('.tab')[0].classList.remove('active');
            document.querySelectorAll('.tab')[1].classList.add('active');
            resetUserTypes('registerForm');
        }
        
        function resetUserTypes(formId) {
            const form = document.getElementById(formId);
            form.querySelectorAll('.user-type').forEach(type => {
                type.classList.remove('active');
            });
            form.querySelector('[data-type="user"]').classList.add('active');
            currentUserType = 'user';
        }
        
        function selectUserType(type) {
            currentUserType = type;
            const activeForm = document.getElementById('loginForm').classList.contains('hidden') ? 
                document.getElementById('registerForm') : document.getElementById('loginForm');
            
            activeForm.querySelectorAll('.user-type').forEach(userType => {
                userType.classList.remove('active');
            });
            activeForm.querySelector(`[data-type="${type}"]`).classList.add('active');
        }
        
        function handleLogin(event) {
            event.preventDefault();
            
            const username = document.getElementById('loginUsername').value;
            const password = document.getElementById('loginPassword').value;
            
            const user = users.find(u => u.username === username && u.password === password && u.type === currentUserType);
            
            if (user) {
                currentUser = user;
                localStorage.setItem('currentUser', JSON.stringify(user));
                showMessage('登录成功！正在跳转...', 'success');
                
                setTimeout(() => {
                    window.location.href = 'home.html';
                }, 1000);
            } else {
                showMessage('用户名或密码错误！', 'error');
            }
        }
        
        function handleRegister(event) {
            event.preventDefault();
            
            const username = document.getElementById('regUsername').value;
            const password = document.getElementById('regPassword').value;
            const phone = document.getElementById('regPhone').value;
            const email = document.getElementById('regEmail').value;
            
            const existingUser = users.find(u => u.username === username);
            if (existingUser) {
                showMessage('用户名已存在！', 'error');
                return;
            }
            
            const newUser = {
                id: users.length > 0 ? Math.max(...users.map(u => u.id)) + 1 : 1,
                username: username,
                password: password,
                phone: phone,
                email: email,
                type: currentUserType,
                name: username,
                registerTime: new Date().toLocaleString()
            };
            
            users.push(newUser);
            localStorage.setItem('users', JSON.stringify(users));
            
            showMessage('注册成功！请登录', 'success');
            
            setTimeout(() => {
                showLogin();
            }, 1500);
        }
        
        function goToMain() {
            if (currentUser) {
                window.location.href = 'home.html';
            }
        }
        
        function logout() {
            localStorage.removeItem('currentUser');
            currentUser = null;
            document.getElementById('loggedInUser').classList.add('hidden');
            document.getElementById('loginForm').classList.remove('hidden');
            document.querySelectorAll('.tab')[0].classList.add('active');
            showMessage('已退出登录', 'success');
        }
        
        function goBack() {
            window.location.href = 'index.html';
        }
        
        // 页面加载时检查登录状态
        window.onload = function() {
            const savedUser = localStorage.getItem('currentUser');
            if (savedUser) {
                currentUser = JSON.parse(savedUser);
                document.getElementById('loggedInUserName').textContent = currentUser.name || currentUser.username;
                document.getElementById('loggedInUser').classList.remove('hidden');
                document.getElementById('loginForm').classList.add('hidden');
                document.getElementById('registerForm').classList.add('hidden');
                document.querySelectorAll('.tab').forEach(tab => tab.classList.remove('active'));
            }
        };
    </script>
</body>
</html>